<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增车辆</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css"
          media="all">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>

</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>新增车辆</legend>
</fieldset>
<form class="layui-form layui-form-pane" action="/Car/CarSave" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label required">名称</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="name" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">类型</label>
        <div class="layui-input-block">
            <input type="text" id="types" name="types" lay-verify="required" lay-reqtext="类型不能为空" placeholder="请输入类型" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">座位数</label>
        <div class="layui-input-block">
            <input type="number" id="sitnum" name="sitnum" lay-verify="required" lay-reqtext="座位数不能为空" placeholder="请输入座位数" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">价格</label>
        <div class="layui-input-block">
            <input type="number" id="price" name="price" lay-verify="required" lay-reqtext="价格不能为空" placeholder="请输入价格" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">数量</label>
        <div class="layui-input-block">
            <input type="number" id="num" name="num" lay-verify="required" lay-reqtext="数量不能为空" placeholder="请输入数量" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">图片地址</label>
        <div class="layui-input-block">
            <input type="text" id="picture" name="picture" lay-verify="required" lay-reqtext="图片地址不能为空" placeholder="请输入图片地址" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <button class="layui-btn" lay-submit lay-filter="saveBtn">添加</button>
    </div>
</form>

<script src="layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'upload', 'element'], function () {
        var form = layui.form,
            upload = layui.upload,
            element = layui.element,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: '/Car/CarSave',
                data: JSON.stringify(data.field),
                type: "post",
                contentType: "application/json",
                dataType: "json",
                success: function (res) {
                    if (res.code==0){
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    }
                }
            });
            return false;
        });
        //重新加载select 标签
        form.render("select");

    });
</script>
</body>
</html>